//
//  LMLeadingViewController.m
//  MyLove
//
//  Created by 贾沙沙 on 15/11/16.
//  Copyright © 2015年 梁佳. All rights reserved.
//

#import "LMLeadingViewController.h"
//#import "LMRecommendViewController.h"
#import "RootTabBarViewController.h"

#define NewfeatureCount 3

@interface LMLeadingViewController ()<UIScrollViewDelegate>

@property (nonatomic, weak) UIPageControl *pageControl;

@end

@implementation LMLeadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //1, 创建一个scrollview, 显示所有的新特性图片
    UIScrollView *scrlloView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    scrlloView.frame = self.view.bounds;
    [self.view addSubview:scrlloView];
    
    //2,添加图片到ScrollView上
    for (int i = 0 ; i < NewfeatureCount; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width * i, 0, CGRectGetWidth(scrlloView.frame), CGRectGetHeight(scrlloView.frame))];
        //显示图片
        NSString *imageName = [NSString stringWithFormat:@"0%d.jpg", i + 1];
        imageView.image = [UIImage imageNamed:imageName];
        [scrlloView addSubview:imageView];
        
        //如果是最后一个imageview就往里面添加其他内容
        if (i == NewfeatureCount - 1) {
            [self setupLastImageView:imageView];
        }
    }
    //默认情况下scrollView一旦创建出来,里面可能就存在一些子控件,,,(就算不主动添加子控件到scrollview中,scrollView内部还是可能会有一些子控件的)
    
    //3,设置scrollView的其他属性
    //如果想让某个方向上不能滚动,那么这个方向上的尺寸传0即可
    scrlloView.contentSize = CGSizeMake(CGRectGetWidth(scrlloView.frame) * NewfeatureCount, 0);
    //去除弹簧效果
    scrlloView.bounces = NO;
    //自动翻页
    scrlloView.pagingEnabled = YES;
    //不显示滑动的条
    scrlloView.showsHorizontalScrollIndicator = NO;
    scrlloView.delegate = self;
}

- (void)setupLastImageView:(UIImageView *)imageView
{
    imageView.userInteractionEnabled = YES;

    UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    startBtn.frame = CGRectMake(0, 400, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 400);
    [startBtn setBackgroundColor:[UIColor clearColor]];
//    [startBtn setTitle:@"点击进入" forState:UIControlStateNormal];
//    [startBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [startBtn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:startBtn];
}
- (void)btnAction
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    RootTabBarViewController *recommendVC = [[RootTabBarViewController alloc] init];
    window.rootViewController = recommendVC;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
